<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="static/lib.js"></script>
<script type="text/javascript" src="static/lib.ext.js"></script>
<script type="text/javascript" src="static/engine.js"></script>
</head>

<body  id="rrrr">
<div>
<input type="text" id="eInShow" size="600" />
<input type="submit" name="button" value="提交" onclick="showEl();" id="btnshow" />
</div>

<div onclick="getEleStation()">
	
    <ul>
        <li>1
          <label for="textfield"></label>
          <input type="text" name="textfield"  value="ddd" />
        </li>
        <li>2</li>
    </ul>
    <form id="form1" name="form1" method="post" action="">
      <label for="textarea"></label>
      <textarea name="textarea" id="textarea" cols="45" rows="5"></textarea>
    </form><p>&nbsp;</p>
   
    <iframe src="untitled2.html" width="5000" height="300"></iframe>
    
<ul>
      <li>3</li>
    </ul>
</div>
</body>
<script type="text/javascript">
// 枚举DOM节点的NodeType类型
if(typeof Node == "undefined")
{
     var Node = 
     {
     	     ELEMENT_NODE: 1,
     	     ATTRIBUTE_NOTE: 2,
     	     TEXT_NODE: 3,
     	     CDATA_SECTION_NODE: 4,
     	     ENTITY_REFERENCE_NOTE: 5,
     	     ENTITY_NODE: 6,
     	     PROCESSING_INSTRUCTION_NOTE: 7,
     	     COMMENT_NODE: 8,
     	     DOCUMENT_NODE: 9,
     	     DOCUMENT_TYPE_NODE: 10,
     	     DOCUMENT_FRAGMENT_NODE: 11,
     	     NOTATION_NODE:12
     }//我们常用的就只有Element Node（元素节点）、Attribute Node（属性节点）、Text Node（文本节点），而这3个中
};
var btnShow = document.getElementById("eInShow");
var getEle  = function(el,rs,doc)
{
	doc = doc || document;
	if(el == document)
		return 'document.'+(rs || 'body');
	var pre = el,i=0;
	
	while(pre = pre.previousSibling)i++;		
	rs = 'childNodes['+i+']'+(rs?'.'+rs:'');
	//rs = 'childNodes.item('+i+')'+(rs?'.'+rs:'');
	if(el.tagName=="HTML")alert(pure.tagName);
	return getEle(el.parentNode,rs,doc);
}
var getDoc2Ele    = function(pre,src)
{
	if(!src)
	{
		src = pre;
		pre = document.body;
	}else
	{
		pre = pre || document.body;
	}
	var oList = [],o=null;
	if(o = pre.firstChild)
	{
		oList.push(o);
		while(o = o.nextSibling)oList.push(o);
	}
	var i = 0,cnt = oList.length,rs = false;
	//alert(cnt);
	///for(i in oList) alert(i);
	for(i = 0;i<cnt;i++)
	{
		o = oList[i];
		//alert(oList[i].tagName+'|'+oList[i].nodeType);
		if(o == src)
		{
			return 'childNodes['+i+']';
			//return [o,i,'childNodes['+i+']'];	
		}else if(o.tagName && o.hasChildNodes())
		{
			if(rs = getDoc2Ele(o,src))
			{
				return 'childNodes['+i+'].'+rs;
				//return [o,i,'childNodes['+i+'].'+rs[2]];
			}
		}else if(o.tagName && o.tagName == "FRAME" || o.tagName == "IFRAME")
		{
			//alert(o.tagName);
			if(o.Document)
			{
				//alert('obj.Document')
				if(rs = getDoc2Ele(o.contentWindow.document.body,src))
				{
					return 'childNodes['+i+'].contentWindow.document.body.'+rs;
				}
			}else
			{
				//alert('obj.contentDocument');
				if(rs = getDoc2Ele(o.contentDocument,src))
				{
					return 'childNodes['+i+'].contentDocument.'+rs;
					//return [o,i,'childNodes['+i+'].'+rs[2]];
				}
			}
		}
				
		//alert(oList[i].tagName+'|'+oList[i].nodeType);
	}
	return false;
	//alert(objNodeList);	
		
}
var getEleStation = function(ev)
{
	ev = ev || window.event;
	if(top.location != self.location)
	{
		window.top.getEleStation(ev);
	}else if(ev)
	{
		var $this = {},pre,i=0;
		var el = "document.body."+getDoc2Ele(ev.srcElement);
		btnShow.value=el;		
	}
	return false;
}

var showEl = function()
{
	alert("innerHTML:"+eval(btnShow.value).innerHTML+"\n"+"value:"+eval(btnShow.value).value+"\n");
}

//btnShow.disabled=true;
//alert(btnShow.nodeType); 
//alert(btnShow.hasChildNodes());
//alert(btnShow.nextSibling.nodeType);
//alert(btnShow.parentNode.tagName);
//alert(document.childNodes[1].tagName);
//alert(document.childNodes[1].childNodes[1].childNodes[1].childNodes[5].contentWindow.document.childNodes[1].childNodes[1].childNodes[1].childNodes[2].childNodes[0].childNodes[2].value)
//var tt= document.childNodes[1].childNodes[1].childNodes[1].childNodes[5];
//alert(document.childNodes[1].childNodes[1].childNodes[1].childNodes[5].tag6Name());
//alert(document.childNodes[1].childNodes[1].childNodes[1].childNodes[5].Document.childNodes[1].childNodes[1].childNodes[1].childNodes[2].childNodes[0].childNodes[2].value);
//alert(document.childNodes[1].childNodes[1].childNodes[1].childNodes[2].childNodes[0].childNodes[2].value);
//alert(document.childNodes[1].childNodes[1].childNodes[1].childNodes[2].childNodes[0].childNodes[2].value);
//alert(document.body.childNodes.item(1).childNodes.item(2).childNodes.item(1).innerHTML);
</script>
</html>